package com.android.gufengmall.adapter;

import android.content.Context;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.android.gufengmall.R;
import com.android.gufengmall.bean.OrderBean;

import java.util.List;

public class CartOrdersAdapter extends RecyclerView.Adapter<CartOrdersAdapter.CartGoodsViewHolder> {

    private Context mContext;
    private List<OrderBean> mOrderBeanList;

    public CartOrdersAdapter(Context context, List<OrderBean> orderBeans) {
        mContext = context;
        mOrderBeanList = orderBeans;
    }

    @NonNull
    @Override
    public CartGoodsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new CartGoodsViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_cart_details,parent,false));
    }

    @Override
    public void onBindViewHolder(@NonNull CartGoodsViewHolder holder, int position) {
        OrderBean orderBean = mOrderBeanList.get(position);

        holder.mImageView.setImageBitmap(BitmapFactory.decodeFile(orderBean.getOrderImgShop()));
        holder.mTvName.setText(orderBean.getOrderName());
        holder.mTvInfo.setText(orderBean.getOrderInfo());
        holder.mTvPrice.setText("￥"+orderBean.getOrderPrice());
        holder.mTvAmount.setText("X"+orderBean.getOrderAmount());
    }

    @Override
    public int getItemCount() {
        return mOrderBeanList.size();
    }

    public class CartGoodsViewHolder extends RecyclerView.ViewHolder {


        private final ImageView mImageView;
        private final TextView mTvName;
        private final TextView mTvInfo;
        private final TextView mTvPrice;
        private final TextView mTvAmount;

        public CartGoodsViewHolder(@NonNull View itemView) {
            super(itemView);

            mImageView = itemView.findViewById(R.id.img_shop);
            mTvName = itemView.findViewById(R.id.tv_name);
            mTvInfo = itemView.findViewById(R.id.tv_info);
            mTvPrice = itemView.findViewById(R.id.tv_price);
            mTvAmount = itemView.findViewById(R.id.tv_amount);
        }
    }
}
